<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<title th:text="鸡天新闻-管理"></title>
<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" th:href="@{../../static/admin/css/bootstrap.min.css}">
  <link rel="stylesheet" type="text/css" th:href="@{../../static/admin/css/style.css}">
  <link rel="stylesheet" type="text/css" th:href="@{../../static/admin/css/font-awesome.min.css}">
  <script th:src="@{../../static/admin/js/jquery-2.1.4.min.js}"></script>
  <script th:src="@{../../static/admin/js/bootstrap.min.js}"></script>
  <script th:src="@{../../static/admin/js/admin-scripts.js}"></script>
  <script th:src="@{../../static/js/md5.js}"></script>
  <script th:src="@{../../static/js/jquery.form.min.js}"></script>
  <script language="JavaScript" th:inline="javascript" type="text/javascript">
    function checkEdit() {
      var oldLoginPwd = document.editUser.oldLoginPwd.value;
      var pwd1 = document.editUser.loginPwd.value;
      var pwd2 = document.editUser.loginPwd1.value;
      var oldPwd = [[${user.getloginPwd()}]];
      if (oldPwd !== hex_md5(oldLoginPwd)) {
        alert("密码错误!");
        return false;
      }
      if (pwd1 !== pwd2) {
        alert("两次输入密码不相同!");
        return false;
      }
      if (pwd1.length < 6) {
        alert("密码长度需大于6!");
        return false;
      }
      return true;
    }
  </script>
</head>
<script language="JavaScript" th:inline="javascript" type="text/javascript">
  function updateEditNews() {
    var newsContent=UE.getEditor('article-content').execCommand( "getlocaldata" );
    var newsTitle=document.updateNews.title.value;
    var userId=[[${user.getuserId()}]];
    var newsWord=document.updateNews.describe.value;
    var auditEditor=[[${user.getuserId()}]];
    var newsType=$("input[name='category']:checked").val();
    var newsStatus=$("input[name='visibility']:checked").val();
    console.log(newsStatus);
    console.log(newsType);
    console.log(userId);
    console.log(auditEditor);
    console.log(newsTitle);
    console.log(newsWord);

    $.ajax({
      url: "http://localhost:8080/newsAPI/add-news",
      data: {
        newsContent:newsContent,
        newsTitle:newsTitle,
        userId:userId,
        newsWord:newsWord,
        auditEditor:auditEditor,
        newsType:newsType,
        newsStatus:newsStatus
      },
      type: "POST",
      dataType: "json",
      async: true,
      success: function (re) {
        alert("添加成功!");
        console.log("success");
        window.location.reload();
      },
      error: function () {
        // alert("error");
        console.log(error());
        window.location.reload();
      }
    });

  }
</script>

<body class="user-select">
<section class="container-fluid">
  <header>
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">切换导航</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
          <a class="navbar-brand" th:href="@{~/admin/index}">AdminSystem</a> </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav navbar-right">
            <li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" th:text="${user.getloginName()}"> <span class="caret"></span></a>
              <ul class="dropdown-menu dropdown-menu-left">
                <li><a title="查看或修改个人信息" data-toggle="modal" data-target="#seeUserInfo">个人信息</a></li>
              </ul>
            </li>
            <li><a th:href="@{~/logout}" onClick="if(!confirm('是否确认退出？'))return false;">退出登录</a></li>
          </ul>
          <form action="" method="post" class="navbar-form navbar-right" role="search">
          </form>
        </div>
      </div>
    </nav>
  </header>
  <div class="row">
    <aside class="col-sm-3 col-md-2 col-lg-2 sidebar">
      <ul class="nav nav-sidebar">
        <li><a th:href="@{~/admin/index}">报告</a></li>
      </ul>
      <ul class="nav nav-sidebar">
        <li><a th:href="@{~/admin/index}">公告</a></li>
        <li><a th:href="@{~/admin/manage-news}">管理文章</a></li>
        <li><a th:href="@{~/admin/manage-user}">管理用户</a></li>
      </ul>
      <ul class="nav nav-sidebar">
        <li><a class="dropdown-toggle" id="settingMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">设置</a>
        </li>
      </ul>
    </aside>
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main">
      <div class="row">
        <form class="add-article-form" name="updateNews">
          <div class="col-md-9">
            <h1 class="page-header">审核修改</h1>
            <div class="form-group">
              <h2 class="add-article-box-title"><span th:text="标题"></span></h2>
              <input type="text" id="article-title" name="title" class="form-control" placeholder="在此处输入标题" required autofocus autocomplete="off">
            </div>
            <div class="form-group">
              <label for="article-content" class="sr-only">内容</label>
              <script id="article-content" name="content" type="text/plain"></script>
            </div>
            <div class="add-article-box">
              <h2 class="add-article-box-title"><span th:text="简介"></span></h2>
              <div class="add-article-box-content">
                <textarea class="form-control" name="describe" autocomplete="off"></textarea>
              </div>
            </div>
          </div>
          <div class="col-md-3">
            <h1 class="page-header">操作</h1>
            <div class="add-article-box">
              <h2 class="add-article-box-title"><span>分类</span></h2>
              <div class="add-article-box-content">
                <ul class="category-list">
                  <li>
                    <label>
                      <input name="category" type="radio" value="1" checked="checked">
                      国内新闻</label>
                  </li>
                  <li>
                    <label>
                      <input name="category" type="radio" value="2" >
                      国际新闻</label>
                  </li>
                  <li>
                    <label>
                      <input name="category" type="radio" value="3">
                      本地新闻</label>
                  </li>
                  <li>
                    <label>
                      <input name="category" type="radio" value="4">
                      娱乐新闻</label>
                  </li>
                  <li>
                    <label>
                      <input name="category" type="radio" value="5">
                      政要新闻</label>
                  </li>
                </ul>
              </div>
            </div>
            <div class="add-article-box">
              <h2 class="add-article-box-title"><span>审核</span></h2>
              <div class="add-article-box-content">
                <p><label>状态：</label><span class="article-status-display" th:text="未审核"></span></p>
                <p><label>审核进度：</label>
                  <input type="radio" name="visibility" value="1" />已审核
                  <input type="radio" name="visibility" value="0" checked="checked"/>未审核</p>
                <p><label>修改于：</label><span class="article-time-display"><input style="border: none;" type="datetime" name="time" th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd HH:mm:ss')}" /></span></p>
              </div>
              <div class="add-article-box-footer">
                <button class="btn btn-primary" type="button" name="submit" onclick="updateEditNews()">更新</button>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</section>
<!--个人信息模态框-->
<div class="modal fade" id="seeUserInfo" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <form id="editUser" th:action="@{~/edit-user}" method="post" name="editUser" onsubmit="return checkEdit()">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" >个人信息</h4>
        </div>
        <div class="modal-body">
          <table class="table" style="margin-bottom:0px;">
            <thead>
            <tr> </tr>
            </thead>
            <tbody>
            <tr>
              <td wdith="20%">用户名:</td>
              <td width="80%"><input type="text" th:value="${user.getloginName()}" class="form-control" name="loginName" maxlength="20" autocomplete="off" readonly="readonly" /></td>
            </tr>
            <tr>
              <td wdith="20%">电话:</td>
              <td width="80%"><input type="text" th:value="${user.getuserPhone()}" class="form-control" name="userPhone" maxlength="20" autocomplete="off" /></td>
            </tr>
            <tr>
              <td wdith="20%">邮箱:</td>
              <td width="80%"><input type="email" th:value="${user.getuserEmail()}" class="form-control" name="userEmail" maxlength="50" autocomplete="off" /></td>
            </tr>
            <tr>
              <td wdith="20%">旧密码:</td>
              <td width="80%"><input type="password" class="form-control" name="oldLoginPwd" maxlength="18" autocomplete="off" /></td>
            </tr>
            <tr>
              <td wdith="20%">新密码:</td>
              <td width="80%"><input type="password" class="form-control" name="loginPwd" maxlength="18" autocomplete="off" /></td>
            </tr>
            <tr>
              <td wdith="20%">确认密码:</td>
              <td width="80%"><input type="password" class="form-control" name="loginPwd1" maxlength="18" autocomplete="off" /></td>
              <td hidden="hidden"><input type="text" hidden="hidden" th:value="${user.getuserType()}" name="userType"></td>
              <td hidden="hidden"><input type="text" hidden="hidden" th:value="${user.getuserId()}" name="userId"></td>
            </tr>
            </tbody>
            <tfoot>
            <tr></tr>
            </tfoot>
          </table>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
          <button type="submit" class="btn btn-primary">提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script th:src="@{../../static/admin/lib/ueditor/ueditor.config.js}"></script>
<script th:src="@{../../static/admin/lib/ueditor/ueditor.all.min.js}"> </script>
<script th:src="@{../../static/admin/lib/ueditor/lang/zh-cn/zh-cn.js}"></script>
<script id="uploadEditor" type="text/plain" style="display:none;"></script>
<script type="text/javascript" language="javascript">
var editor = UE.getEditor('article-content');
window.onresize=function(){
  window.location.reload();
};
var _uploadEditor;
$(function () {
  //重新实例化一个编辑器，防止在上面的editor编辑器中显示上传的图片或者文件
  _uploadEditor = UE.getEditor('uploadEditor');
  _uploadEditor.ready(function () {
    //设置编辑器不可用
    //_uploadEditor.setDisabled();
    //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
    _uploadEditor.hide();
    //侦听图片上传
    _uploadEditor.addListener('beforeInsertImage', function (t, arg) {
      //将地址赋值给相应的input,只去第一张图片的路径
      $("#pictureUpload").attr("value", arg[0].src);
      //图片预览
      //$("#imgPreview").attr("src", arg[0].src);
    })
    //侦听文件上传，取上传文件列表中第一个上传的文件的路径
    _uploadEditor.addListener('afterUpfile', function (t, arg) {
      $("#fileUpload").attr("value", _uploadEditor.options.filePath + arg[0].url);
    })
  });
});
//弹出图片上传的对话框
$('#upImage').click(function () {
  var myImage = _uploadEditor.getDialog("insertimage");
  myImage.open();
});
//弹出文件上传的对话框
function upFiles() {
  var myFiles = _uploadEditor.getDialog("attachment");
  myFiles.open();
}
</script>
</body>
</html>